<!-- 搜索表单 -->
<template>
    <el-card shadow="never" >
      <el-form
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="search"
        @submit.native.prevent
      >
        <el-row :gutter="15">
          <el-col :lg="5" :md="12">
            <el-form-item label="关键字:" label-width="60px">
              <el-input clearable v-model="where.keyword" placeholder="支持订单号,合同号，提单号模糊查询" />
            </el-form-item>
          </el-col>
          <el-col :lg="5" :md="12">
            <el-form-item label="供应商:" label-width="60px">
              <el-select v-model="where.supplierId" clearable placeholder="请输入供应商">
                <el-option v-for="(item, index) in supplierDatas" :key="index" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="制单日期:">
              <el-date-picker v-model="where.createDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="daterange"
                  range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width:240px">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="12">
            <el-form-item label="状态:">
              <el-select v-model="where.status" clearable placeholder="请输入状态">
                <el-option v-for="(item, index) in statusEnums" :key="index" :label="item.Value" :value="item.Key" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="12">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                @click="search"
              >
                查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    </template>
    
    <script>
      const DEFAULT_WHERE = {
        keyword: '',  //关键字
        createDate:'',
        status:'',
      };
      import { QueryPurOrderEnum } from '@/api/enummanger';
      import { GetAllBSupplier } from '@/api/basicdatamanager/supplier';
      export default {
        name: 'PurOrderSearch',
       
        data() {
          return {
            // 表单数据
            where: { ...DEFAULT_WHERE },
            statusEnums:[],
            supplierDatas:[],
          };
        },
        //初始化数据
        created(){
         this.queryStatusEnums();
        },
    
        methods: {
    
          /* 搜索 */
          search() {
            let params = {
              pageindex: 1,
              conditions: [],
              orderBys: [{ sort: "createDate", order: 1, }],
            };
    
            //关键字查询
            if(this.where.keyword){
              params.conditions.push({
                key:"orderNo,contractNumber,billNumber",
                operator: 1,
                value: this.where.keyword,
              });
            };

            //关键字查询
            if(this.where.supplierId){
              params.conditions.push({
                key:"supplierId",
                operator: 0,
                value: this.where.supplierId,
              });
            };

            //状态查询
            if(this.where.status){
              params.conditions.push({
                key:"status",
                operator: 0,
                value: this.where.status,
              });
            };

            //制单日期
            if(this.where.createDate){
              params.conditions.push({
                key:"createDate",
                operator: 3,
                value:  this.where.createDate[0] + " 00:00:00",
              });

              params.conditions.push({
                key:"createDate",
                operator: 5,
                value:  this.where.createDate[1] + " 23:59:59",
              });
            };
    
            this.$emit('search', params);
          },
          /*  重置 */
          reset() {
            this.where = { ...DEFAULT_WHERE };
            this.search();
          },
    
          /* 系统状态 */
          async queryStatusEnums(){
            let sysEnums = await QueryPurOrderEnum();
            sysEnums.map(e=>{
              this.statusEnums.push({Key:e.Key,Value:e.Value});
            });


            GetAllBSupplier().then((d)=>{
              this.supplierDatas = [];
              this.supplierDatas = d;
            })
          },
        }
      };
    </script>
    